<%--
  Created by IntelliJ IDEA.
  User: User
  Date: 2020/5/7
  Time: 11:13
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>关键字搜索</title>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-3.4.1.min.js"></script>
    <style>
        li{
            list-style: none;
            font-size: 14px;
        }
        #d{
            border: 1px solid #dddddd;
            width: 260px;
            padding: 3px 5px;
            border-top: 0px;
            max-height: 100px;
            overflow: auto;
            display: none;
        }
    </style>
    <script>
        $(function(){
            $("#spell").keyup(function(){
                $("#d").empty();
                if($(this).val() == ""){
                    $("#d").hide();
                    return;
                }
               $.ajax({
                   type:"post",
                   url:"${pageContext.request.contextPath}/ajax/query",
                   data:{"spell":$(this).val()},
                   dataType:"json",
                   success:function(datas){
                       if(datas.length == 0){
                           $("#d").hide();
                           return;
                       }
                       $("#d").show();
                       $(datas).each(function(){
                           $("#d").append("<li>"+this.message+"</li>");
                       });
                   }
               })
            });
        });
    </script>
</head>
<body>
<input type="text" style="width: 272px;" id="spell">
<div id="d">
</div>
</body>
</html>